home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
nvdc87
/
lcv1n1
/
mean2.pro
< prev
next >
Wrap
Text File
|
1987-08-11
|
920b
|
33 lines
/* Listing 6 - Mean in PROLOG without tail recursion elimination */
domains
real_list = real*
database
answer(real)
data(integer,real_list)
predicates
process(real_list)
mean(real_list,real,integer)
clauses
process(List):-
N=0,
S=0,
mean(List,S,N), /* Call Turbo PROLOG function. */
answer(Answer), /* to calculate the mean. */
write(Answer). /* Get the answer from the answer and */
/* report. */
mean([],_,_).
mean([H|T],S,N):-
Y=H+S,
N2=N+1,
mean(T,Y,N2),
T = [], /* These lines force mean to */
Z=Y/N2, /* remember an address each time */
assert(answer(Z)). /* it calls itself recursively. */
mean([_|_],_,_). /* We need this line to make */
/* mean always succeed. */